home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_C / SPELL__ / PCKCHECK.C < prev    next >
C/C++ Source or Header  |  1990-07-03  |  3KB  |  111 lines

  1. /*
  2.  
  3.     File:          pckcheck.c
  4.     Author:        Graham Toal
  5.     Purpose:       check correct spelling using dict.pck
  6.     Creation date: 22/06/90
  7.     Lastedit:      23/06/90 01:15:39
  8.  
  9.     Description:
  10.  
  11.        This can be expanded to be like the unix 'spell' command.
  12.     This demo file simply checks words passed on the command line.
  13.     note how it remembers words so that the second time it sees
  14.     them, it will call them correct.  This is how you should
  15.     implement the 'ignore' feature of an interactive checker.
  16.  
  17.     This version used the fast 'packed' data structure.  This is
  18.     approximately 3 times faster, but not all utilities support
  19.     the packed versions.  Also utilities which walk the trie are
  20.     considerably slower (say by a factor of 100) -- so chose when
  21.     to used 'dawg' and when to use 'pack'ed versions carefully!
  22.  
  23. */
  24.  
  25.  
  26. /* Manadatory header files */
  27. #include <stdio.h>
  28. #include "dawg.h"
  29. #include "grope.h"
  30.  
  31. /*#define RCHECK*/     /* Enable for internal range checks... */
  32.  
  33. #include "utils.c"
  34.  
  35. /* Headers here as needed on per-program basis */
  36. #include <ctype.h>  /* eg, for isalpha() */
  37.  
  38. /* Spelling library utilities */
  39. #include "init.c"      /* Loading dicts */
  40. #include "dyntrie.c"   /* Creating dicts at run-time */
  41. #include "print.c"     /* Printing dicts */
  42. #include "check.c"     /* Checking words */
  43. #include "locate.c"    /* Finding words by their stems */
  44.  
  45. #include "soundex.c"   /* Soundex algorithm for word-likeness comparison */
  46. #include "similcmp.c"  /* Closeness-metric for correction */
  47. #include "correct.c"   /* Hack code to attempt error correction (uses above) */
  48.  
  49. /* Let's be friendly to these guys... */
  50. #ifdef SYS_MAC
  51. /* To compile with THINK C 4.0, place all the relevant .h and .c
  52.    files in a folder.  Then create a project which contains this main.c
  53.    and the libraries unix and ANSI.
  54. */
  55. #include <unix.h>
  56. #include <stdlib.h>
  57. #include <console.h>
  58. #endif
  59.  
  60. /* Your own header files go here, for instance:
  61.                #include "readword.h"
  62.  */
  63.  
  64.  
  65.  
  66. int
  67. #ifdef PROTOTYPES
  68. main(int argc, char **argv)
  69. #else
  70. main(argc, argv)
  71. int argc;
  72. char **argv;
  73. #endif
  74. {
  75. NODE PCCRAP *ptrie;     /* precompiled dictionary (dict.pck) */
  76. INDEX edges;            /* size of above */
  77.  
  78. NODE PCCRAP *userdict;  /* run-time dictionary, added to dynamically */
  79.  
  80. char *word;
  81. int each;
  82.  
  83. #ifdef SYS_MAC
  84.   argc = ccommand(&argv);  /* Mac users have my sympathy */
  85. #endif
  86.  
  87.   /* Your program goes here... */
  88.   if (argc == 1) {
  89.     fprintf(stderr, "usage: %s possibly mispeled wurdz\n", argv[0]);
  90.     exit(EXIT_ERROR);
  91.   }
  92.  
  93.   if (!pack_init("", &ptrie, &edges)) exit(EXIT_ERROR);
  94.  
  95.   if (!trie_new(&userdict)) exit(EXIT_ERROR);
  96.  
  97.   for (each = 1; each < argc; each++) {
  98.     word = argv[each];
  99.     fprintf(stderr, "* %s:\n", word);
  100.     if (pack_check(ptrie, word) || dawg_check(userdict, word)) {
  101.       fprintf(stderr, "Correct\n");
  102.     } else {
  103.       fprintf(stderr, "Wrong\n");
  104.       (void)trie_add(&userdict, word);
  105.     }
  106.     if (each+1 != argc) fprintf(stderr, "\n");
  107.   }
  108.  
  109.   exit(EXIT_OK);
  110. }
  111.